#include "Bullet.h"


CBullet::CBullet(void)
{

}
CBullet::CBullet(float x, float y, float vx, float vy, int deltaTime,int resourceName,CResourceManager* rm):MObject(x,y,vx,vy,deltaTime,resourceName,rm)
{
	_vx = vx;
	if (_vx > 0)
		_vx = 1.f;
	else _vx = -1.f;

	_status = STATUS_ALIVE;
	_objectType = CResourceManager::TYPE_BULLET;
}

void CBullet::Move()
{
	switch (_status)
	{
	case (STATUS_ALIVE):
		{
			if (_vy < 2.f)
				_vy += 0.1f;

			if (_percent > 0)
			{
					_x += _vx*_percent*_deltaTime;
					_y += _vy*_percent*_deltaTime;
			}
			else
			{
				_x += _vx*_deltaTime;
				_y += _vy*_deltaTime;
			}

			break;
		}
	}
	_percent = 0;
}
void CBullet::Render()
{
	if (_status == STATUS_ALIVE)
		MObject::Render();
}

CBullet::~CBullet(void)
{
	//delete _sprite;
}

void CBullet::setVelocity(Vector v, shared_ptr<MObject> Object){};

void CBullet::actAfterCollided(int Direction, shared_ptr<MObject> Object)
{
	switch (Direction)
	{
	case 1://UP
		{
			_vy = - 1.f;
			break;
		}
	case 2://DOWN
		{
			break;

		}
	case 3://RIGHT
	case 4://LEFT
		{
			//if (abs(_vy) >= 0.4f)
				setStatus(STATUS_DEAD);
			break;
		}
	}
}

void CBullet::setStatus(int Status)
{
	MObject::setStatus(Status);
}